//获取点击菜单；
var mu="m1";
//搜索条件
var querystr=null;
//
var memberId;



//在线咨询
function tochat(memberid){
    server.loadindex('page/chat/chat','teacherTopicID='+memberid);
};
//去老师详情页
function todetail(teacherid) {
    if(server.isEmpty(teacherid)){
        pop_up("专家ID为空，不能继续");
        return;
    }
    server.loadindex('page/teacher/teacherdetail/teacherdetail','teachid='+teacherid,true);
};
//去回答闪测问题页面
function quickAskHistory(orderId) {
    if(server.isEmpty(orderId)){
        pop_up("获取订单ID失败，请联系管理员");
        return;
    }
    server.loadindex('page/quickask/historyQuickAsk/historyQuickAsk','orderId='+orderId,true);
}
// $(function () {
function writeHtml(data){
    var strHtml = "";
    var strStatus="";
    var strChat="";
    var strQuickAskReply="";
    var strQuickAskHistory="";
// console.log(data)
    $("#Corder-list").html("");
    data.forEach(function (orderitem, index) {
        var strGoods = "";
        strChat="";
        strQuickAskHistory="";
        var goods = orderitem.goods;

        var strOrderType = "咨询订单";

        if (goods)
            goods.forEach(function (item, id) {

                strGoods = strGoods + '<div class="order-list-item-goods">\n' +
                    '                            <div class="order-list-item-goods-image">\n' +
                    '                                <img src="img/icons/default.png" />\n' +
                    '                            </div>\n' +
                    '                            <div class="order-list-item-goods-title">\n' +
                    '                                <label data-item="itemName">' + item.itemName + '</label>\n' +
                    '                            </div>\n' +
                    '                            <div class="order-list-item-goods-price">\n' +
                    '                                <label data-item="discountPrice">' + item.discountPrice + '</label>\n' +
                    '                            </div>\n' +
                    '                        </div>'
            });


            //写html
            if(orderitem.status==0){
                strStatus="待付款";
            }else  if(orderitem.status==1){
                strStatus="服务中";
                if(orderitem.serviceType==1){
                    strChat= '                    <div class="order-list-item-btns-btn" onclick="tochat('+orderitem.memberId+')">\n' +
                        '                        <label>在线咨询</label>\n' +
                        '                    </div>\n';
                }else if(orderitem.serviceType==2){
                    // strQuickAskReply= '                    <div class="order-list-item-btns-btn" onclick="replyQuickAsk()">\n' +
                    //     '                        <label>回答提问</label>\n' +
                    //     '                    </div>\n';
                    strQuickAskHistory='<div class="order-list-item-btns-btn" onclick="quickAskHistory('+orderitem.id+')">\n' +
                    '                        <label>专家建议</label>\n' +
                    '                    </div>\n';
                }
            }else if(orderitem.status==2){
                strStatus="待评价";
            }else if(orderitem.status==3){
                strStatus="已完成";
            }else if(orderitem.status==-1){
                strStatus="已取消";
            }else if(orderitem.status==-2){
                strStatus="申请退款";
            }else if(orderitem.status==-3){
                strStatus="已退款";
            };
            //翻译订单类型
            if(orderitem.serviceType==1){
                strOrderType="咨询订单";
            }else if(orderitem.serviceType==2){
                strOrderType="闪测订单";
            }else if(orderitem.serviceType==3){
                strOrderType="提问订单";
            }else if(orderitem.serviceType==4){
                strOrderType="充值订单";
            }

            strHtml = strHtml + '<div class="order-list-item">\n' +
                '                <div class="order-list-item-status">\n' +
                '                    <img src="' + orderitem.memberHeadimgurl + '" />\n' +
                '                    <label style="margin-left:3px;font-weight: bold">' + orderitem.memberName +'('+strOrderType+ ')</label><label style="float:right;margin-right:10px">' + strStatus+ '</label>\n' +
                '                </div>\n' +
                '                <div class="Corder-list-item-goods{{id}}">\n' +
                '                    <div data-for="goods">\n' +
                strGoods +
                '                    </div>\n' +
                '                </div>\n' +
                '                <div class="order-list-item-btns">\n' +
                strChat+strQuickAskHistory+
                '                </div>\n' +

                '                <div class="order-list-item-time">\n' +
                '                    <label data-item="createDate">'+orderitem.createDate+'</label><label style="margin-left: 10px">NO:</label><label data-item="orderNo">'+orderitem.orderNo+'</label>\n' +
                '                </div>\n' +
                '            </div>';


                $("#Corder-list").html(strHtml);


    })


};


    function loadData(querystr){
        server.req('wechat/order/teacherlist',querystr,function (res) {
            console.log(res);
            if(res.code==0){
                var data = res.data;

                writeHtml(data);
            }
        })
        // server.req('wechat/order/list',querystr,function (res) {
        //     console.log(res);
        //     if(res.code==0){
        //         var data = res.data;
        //         writeHtml(data);
        //
        //
        //     }
        //
        // })
    }
//切换菜单
    function initMenu() {
        $("#m1").css('color','black');
        $("#m1").css('font-weight','normal');
        $("#m2").css('color','black');
        $("#m2").css('font-weight','normal');
        $("#m3").css('color','black');
        $("#m3").css('font-weight','normal');
        $("#m4").css('color','black');
        $("#m4").css('font-weight','normal');
    }
    function menu(e) {
        initMenu();
        $("#"+e).css('color','red');
        $("#"+e).css('font-weight','bold');

        if(e=='m1'){
            loadData(null);
        }else if(e=='m2'){
            querystr={};
            querystr.status=0;
            loadData(querystr);
        }
        else if(e=='m3'){
            querystr={};
            querystr.status=1;
            loadData(querystr);
        }
        else if(e=='m4'){
            querystr={};
            querystr.status=2;
            loadData(querystr);
        }
    };



    // loadData(querystr);
    mu = server.getQueryString("menu");
    if(server.isEmpty(mu)){
        mu="m1";
    }
    menu(mu);


// })


